using UnityEngine;
using System.Collections;

public class Cube : MonoBehaviour
{
    public Vector3 FrameCenter;
    public float RotationSpeed = 90.0f;

    protected bool IsRotationStarted;
    protected float RotatedAngle = 0;

    // Use this for initialization
    protected void Start()
    {
        IsRotationStarted = false;
    }

    // Update is called once per frame
    protected void Update()
    {

    }

    // interface: call to start the cube rotation 90 degrees
    // Input:   
    //      vAxis: which axis to rotate
    //      bDirection: which direction Clockwise or Counter Clockwise
    // Output:
    //      bool: if it is still rotating. Return false if the rotation
    //          if finished.
    public bool CubeRotation( Vector3 vAxis, bool bIsPositive )
    {
        if ( IsRotationStarted )
        {
            float angle = RotationSpeed * Time.deltaTime;
            if ( RotatedAngle + angle >= 90 )
            {
                angle = 90 - RotatedAngle;
                IsRotationStarted = false;
            }
            else
            {
                RotatedAngle += angle;
            }
            transform.RotateAround( FrameCenter, vAxis, angle );
        }
        return IsRotationStarted;
    }

    public virtual void SetCubeRotationStart( )
    {
        IsRotationStarted = true;
        RotatedAngle = 0;
    }

    public bool GetCubeRotationStatus()
    {
        return IsRotationStarted;
    }
}
